home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / lib / rcscripts / addons / udev-stop.sh < prev   
Text File  |  2006-05-02  |  2KB  |  69 lines

  1. # Copyright 1999-2005 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3.  
  4. main() {
  5.     if [[ -e /dev/.devfsd || ! -e /dev/.udev || ! -z ${CDBOOT} || \
  6.        ${RC_DEVICE_TARBALL} != "yes" ]] || \
  7.        ! touch /lib/udev-state/devices.tar.bz2 2>/dev/null
  8.     then
  9.         return 0
  10.     fi
  11.         
  12.     ebegin "Saving device nodes"
  13.     # Handle our temp files
  14.     devices_udev=$(mktemp /tmp/devices.udev.XXXXXX)
  15.     devices_real=$(mktemp /tmp/devices.real.XXXXXX)
  16.     devices_totar=$(mktemp /tmp/devices.totar.XXXXXX)
  17.     device_tarball=$(mktemp /tmp/devices-XXXXXX)
  18.     
  19.     if [[ -z ${devices_udev} || -z ${devices_real} || \
  20.           -z ${devices_totar} || -z ${device_tarball} ]] ; then
  21.         eend 1 "Could not create temporary files!"
  22.     else
  23.         cd /dev
  24.         # Find all devices
  25.         find . -xdev -type b -or -type c -or -type l | cut -d/ -f2- > \
  26.             "${devices_real}"
  27.         # Figure out what udev created
  28.         eval $(grep '^[[:space:]]*udev_db=' /etc/udev/udev.conf)
  29.         if [[ -d ${udev_db} ]]; then
  30.             # New udev_db is clear text ...
  31.             udevinfo=$(cat "${udev_db}"/*)
  32.         else
  33.             # Old one is not ...
  34.             udevinfo=$(udevinfo -d)
  35.         fi
  36.         # This basically strips 'S:' and 'N:' from the db output, and then
  37.         # print all the nodes/symlinks udev created ...
  38.         echo "${udevinfo}" | gawk '
  39.             /^(N|S):.+/ {
  40.                 sub(/^(N|S):/, "")
  41.                 split($0, nodes)
  42.                 for (x in nodes)
  43.                     print nodes[x]
  44.             }' > "${devices_udev}"
  45.         # These ones we also do not want in there
  46.         for x in MAKEDEV core fd initctl pts shm stderr stdin stdout; do
  47.             echo "${x}" >> "${devices_udev}"
  48.         done
  49.         fgrep -x -v -f "${devices_udev}" < "${devices_real}" > "${devices_totar}"
  50.         # Now only tarball those not created by udev if we have any
  51.         if [[ -s ${devices_totar} ]]; then
  52.             # we dont want to descend into mounted filesystems (e.g. devpts)
  53.             # looking up username may involve NIS/network, and net may be down
  54.             try tar --one-file-system --numeric-owner -jcpf "${device_tarball}" -T "${devices_totar}"
  55.             try mv -f "${device_tarball}" /lib/udev-state/devices.tar.bz2
  56.         else
  57.             rm -f /lib/udev-state/devices.tar.bz2
  58.         fi
  59.         eend 0
  60.     fi
  61.  
  62.     rm -f "${devices_udev}" "${devices_real}" "${devices_totar}" "${device_tarball}"
  63. }
  64.  
  65. main
  66.  
  67.  
  68. # vim:ts=4
  69.